package com.wyx.suanfa;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author 王艺锡
 * @version 1.0
 */
public class rob {
    //你是一个专业的小偷，计划偷窃沿街的房屋。每间房内都藏有一定的现金，影响你偷窃的唯一制约因素就是相邻的房屋装有相互连通的防盗系统，如果两间相邻的房屋在同一晚上被小偷闯入，系统会自动报警。
    //
    //给定一个代表每个房屋存放金额的非负整数数组，计算你 不触动警报装置的情况下 ，一夜之内能够偷窃到的最高金额。
    //
    //
    public static void main(String[] args) {

        ExecutorService service = Executors.newFixedThreadPool(5);
        CountDownLatch latch = new CountDownLatch(2);
        CyclicBarrier cyclicBarrier = new CyclicBarrier(2);

        service.submit(() -> {
            System.out.println("task1 begin");
            try {
                Thread.sleep(1000);
                cyclicBarrier.await();
                System.out.println("task1 end");
            } catch (Exception e) {
                e.printStackTrace();
            }

        });

        service.submit(() -> {
            System.out.println("task2 begin");
            try {
                Thread.sleep(2000);
                cyclicBarrier.await();
                System.out.println("task2 end");
            } catch (Exception e) {
                e.printStackTrace();
            }
        });


    }
}
/*
* class Solution {
    public int rob(int[] nums) {
        if(nums.length == 0 || nums == null){
            return 0;
        }
        if(nums.length == 1){
            return nums[0];
        }
        int[] dp = new int[nums.length];
        dp[0] = nums[0];
        dp[1] = Math.max(nums[0],nums[1]);


        for(int i = 2;i< dp.length;i++){
            dp[i] = Math.max(dp[i - 2] + nums[i],dp[i - 1]);
        }

        return dp[nums.length - 1];
    }
}*/
